require 'gnuplot'

class F8

 def initialize(inicio, fim)
 	@inicio = inicio
 	@fim = fim
 end
 
 def calcula(x)
 	sum = 0
 	(1..10).each do |e|
 		sum += (((x+e) ** 2)/4000)
 	end
 		
 	prod = 1
 	(1..10).each do |v|
 		prod = prod * Math.cos((x+v)/(Math.sqrt(v)))
 	end
 	
 	(1 + sum - prod)
 end
 
 def valores_range
 	@arr = []
 	(@inicio..@fim).each do |v|
 		@arr << self.calcula(v)
 	end
 	return @arr
 end
 
 def plotar 	
 	Gnuplot.open do |gp|
  		Gnuplot::Plot.new( gp ) do |plot|
  
    	plot.title  "F8"
    	plot.ylabel "F8(x)"
    	plot.xlabel "x"
    
    	x = (@inicio..@fim).collect { |v| v.to_f }
    	y = x.collect { |v| self.calcula(v) }

    	plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
      		ds.with = "linespoints"
    	  	ds.notitle
	    end
	  end
	end 	
 end

end
